void main() {
  // 当前时间
  var now = new DateTime.now();
  print(now);

// 创建时间
  var date = new DateTime(2024, 12, 32, 22, 40);
  print(date);

  // 创建标准时间
  var date2 = DateTime.parse('2024-12-31 22:40:30');
  print(date2);

  var date3 = DateTime.parse('2024-12-31 22:40:30+0800');
  print(date3);

  // 时间增量
  print(now.add(new Duration(hours: 2)));
  print(now.add(new Duration(hours: -3)));

  // 时间比较
  // date 是否 date2 之后
  print(date.isAfter(date2));
  // date2 是否 date3 之前
  print(date2.isBefore(date3));
  // date2 是否 date3 相等
  print(date2.isAtSameMomentAs(date3));

  // 时间差
  var date4 = new DateTime(
    2025,
    1,
    1,
  );

  var date5 = new DateTime(
    2025,
    1,
    28,
  );

  var difference = date4.difference(date5);
  print([difference.inDays, difference.inHours]); // date4 与 date5 相差的天数与小时

  // 时间戳
  print(now.millisecondsSinceEpoch); // 单位毫秒，13位时间戳
  print(now.microsecondsSinceEpoch); // 单位微秒，16位时间戳

  // 格式化
  print(now.month.toString().padLeft(2, '0'));

  String timestamp =
      "${now.year.toString()}-${now.month.toString().padLeft(2, '0')}-${now.day.toString().padLeft(2, '0')} ${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}";

  print(timestamp);
}
